//
//  ConnectTableViewCell.m
//  BaseApp
//
//  Created by 王增战 on 2017/1/6.
//  Copyright © 2017年 Romens. All rights reserved.
//

#import "ConnectTableViewCell.h"

@implementation ConnectTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.avatarView = [[UIImageView alloc] init];
        self.avatarView.translatesAutoresizingMaskIntoConstraints = false;
        self.avatarView.layer.cornerRadius = 20;
        self.avatarView.clipsToBounds = YES;//裁边
        self.avatarView.backgroundColor = [UIColor blackColor];
        [self.contentView addSubview:self.avatarView];
        
        self.avatarLab = [[UILabel alloc] init];
        self.avatarLab.translatesAutoresizingMaskIntoConstraints = NO;
        self.avatarLab.textAlignment = NSTextAlignmentCenter;
        self.avatarLab.font = BoldSystemFont(20);
        self.avatarLab.textColor = [UIColor whiteColor];
        self.avatarLab.layer.backgroundColor = HXSystemColor.CGColor;
        self.avatarLab.layer.cornerRadius = 20;
        self.avatarLab.clipsToBounds = YES;//裁边
        self.avatarLab.hidden = YES;
        [self.contentView addSubview:self.avatarLab];
        
        self.nameLab = [[UILabel alloc] init];
        self.nameLab.translatesAutoresizingMaskIntoConstraints = false;
        self.nameLab.font = systemFont(17);
        self.nameLab.textAlignment = NSTextAlignmentLeft;
        [self.contentView addSubview:self.nameLab];
        
        self.line = [[UIView alloc] init];
        self.line.translatesAutoresizingMaskIntoConstraints = NO;
        self.line.backgroundColor = [UIColor colorWithRed:207 / 255.0 green:210 /255.0 blue:213 / 255.0 alpha:0.7];//cell间线的颜色
        [self.contentView addSubview:self.line];

        [self layoutSubviews];
    }
    return self;
}
- (void)layoutSubviews {
    [super layoutSubviews];

    [self.contentView addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(_avatarView,_nameLab) format:@"H:|-15-[_avatarView(40)]-10-[_nameLab]"]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_avatarView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:-20]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_avatarView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:20]];
    
    [self.contentView addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(_avatarLab,_nameLab) format:@"H:|-15-[_avatarLab(40)]-10-[_nameLab]"]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_avatarLab attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:-20]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_avatarLab attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:20]];
    
    [self.contentView addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(_nameLab) format:@"V:|-5-[_nameLab]-5-|"]];
    //line
    [self.contentView addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(_line) format:@"H:|-15-[_line]|"]];
    [self.contentView addConstraints:[ToolHelper GetNSLayoutCont:NSDictionaryOfVariableBindings(_line) format:@"V:[_line(1)]|"]];
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
